<?php

namespace app\admin\controller;

use app\admin\model\KuaiDiUserModel;
use app\admin\model\QjUserModel;
use think\Controller;
use think\Request;


class Login extends Controller {

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    //登陆
    public function index(){
        $user_name = input('user_name', '');
        $password = input('password', '');
        $adminModel = new KuaiDiUserModel();
        $res = $adminModel->getUserInfo($user_name, $password);
        return json($res);
    }

    public function checkLogin()
    {
        $token = getHeader('Token', '');
        if (empty($token)) {
            $res['success'] = false;
            $res['desc'] = '登录态失效';
            $res['errorcode'] = '-1';
            return json_encode($res);
        }

        $info = \think\Cache::get($token);
        if(empty($info)){
            $res['success'] = false;
            $res['desc'] = '登录态失效';
            $res['errorcode'] = '-1';
            return json_encode($res);
        }
        $res['success'] = true;
        $res['desc'] = '';
        $res['errorcode'] = '';
        return json_encode($res);
    }

    public function outLogin()
    {
        $token = getHeader('Token', '');
        if (!empty($token)) {
            \think\Cache::rm($token);
        }
        $res['success'] = true;
        $res['desc'] = '';
        $res['errorcode'] = '';
        return json_encode($res);
    }

    
}
